package com.sudo.api.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@Configuration
public class CrossConfig {
    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        //config.addAllowedOrigin("http://www.iam.sudo:8080");
        config.addAllowedOriginPattern("*");
        //放行哪些原始请求头部信息
        config.addAllowedHeader("*");
        //放行哪些请求方式
        config.addAllowedMethod("*");
        //是否发送Cookie
        config.setAllowCredentials(true);
        //2. 添加映射路径
        UrlBasedCorsConfigurationSource crossConfigurationSource = new UrlBasedCorsConfigurationSource();
        crossConfigurationSource.registerCorsConfiguration("/**", config);
        return new CorsFilter(crossConfigurationSource);
    }
}
